package com.example.image.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class AdapterShowSelect extends BaseAdapter {

	private Context context;
	private ArrayList<Drawable> list;

	public AdapterShowSelect(Context context, ArrayList<Drawable> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Drawable getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView iv = new ImageView(context);
		iv.setAdjustViewBounds(true);
		iv.setImageDrawable(getItem(position));
		return iv;
	}

	/**
	 * 把指定位置的drawable转换成bitmap
	 * 
	 * @param position
	 * @return
	 */
	public Bitmap getBitmap(int position) {
		BitmapDrawable bd = (BitmapDrawable) list.get(position);
		return bd.getBitmap();
	}

	/**
	 * 把指定位置的drawable转换成currentbitmap的drawable格式
	 * 
	 * @param position
	 * @param currentBitmap
	 */
	public void setBitmap(int position, Bitmap currentBitmap) {
		Drawable drawable = new BitmapDrawable(null, currentBitmap);
		list.set(position, drawable);
		notifyDataSetChanged();
	}

}
